package com.neusoft.controller;

import com.neusoft.po.CommonResult;
import com.neusoft.po.Food;
import com.neusoft.service.FoodService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/FoodController")
@RefreshScope       //开启动态刷新
public class FoodController {

    @Autowired
    private FoodService foodService;

    @GetMapping("/listFoodByBusinessId/{businessId}")
    public CommonResult<List<Food>> listFoodByBusinessId(@PathVariable("businessId") Integer businessId)
            throws Exception {
        List<Food> list = foodService.listFoodByBusinessId(businessId);
        return new CommonResult<>(200, "success", list);
    }

    @GetMapping("/getFoodById/{businessId}/{foodId}")
    public CommonResult<Food> getFoodById(@PathVariable("businessId") Integer businessId,
                                          @PathVariable("foodId") Integer foodId) throws Exception {
        Food food = foodService.getFoodById(foodId);
        return new CommonResult<>(200, "success", food);
    }
}